<template>
  <div id="app">
    <!-- 产品介绍页不需要头部导航 -->
    <template v-if="$route.name === 'Landing'">
      <router-view />
    </template>
    
    <!-- 认证页面不需要头部导航 -->
    <template v-else-if="['Login', 'Register'].includes($route.name)">
      <router-view />
    </template>
    
    <!-- 主应用页面 -->
    <template v-else>
      <el-container>
        <el-header class="app-header">
          <div class="header-content">
            <h1 class="app-title">
              <el-icon><House /></el-icon>
              智能装修设计系统
            </h1>
            <div class="header-actions">
              <el-button type="primary" @click="$router.push('/home')">
                <el-icon><HomeFilled /></el-icon>
                首页
              </el-button>
              <el-button @click="$router.push('/history')">
                <el-icon><Clock /></el-icon>
                历史记录
              </el-button>
              <el-dropdown @command="handleUserCommand">
                <span class="user-info">
                  <el-icon><User /></el-icon>
                  {{ user?.phone }}
                  <el-icon><ArrowDown /></el-icon>
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item command="profile">个人中心</el-dropdown-item>
                    <el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </div>
        </el-header>
        
        <el-main class="app-main">
          <router-view />
        </el-main>
        
        <el-footer class="app-footer">
          <div class="footer-content">
            <p>&copy; 2024 智能装修设计系统. 基于AI技术的智能装修方案生成平台.</p>
          </div>
        </el-footer>
      </el-container>
    </template>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useAuthStore } from '@/stores/auth'
import { House, HomeFilled, Clock, User, ArrowDown } from '@element-plus/icons-vue'

const router = useRouter()
const authStore = useAuthStore()

const user = computed(() => authStore.user)

const handleUserCommand = async (command) => {
  if (command === 'logout') {
    try {
      await ElMessageBox.confirm('确定要退出登录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      
      await authStore.logout()
      ElMessage.success('已退出登录')
      router.push('/')
    } catch (error) {
      if (error !== 'cancel') {
        ElMessage.error('退出登录失败')
      }
    }
  } else if (command === 'profile') {
    ElMessage.info('个人中心功能开发中...')
  }
}
</script>

<style scoped>
.app-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  padding: 0 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.app-title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.user-info:hover {
  background: rgba(255, 255, 255, 0.2);
}

.app-main {
  min-height: calc(100vh - 120px);
  background-color: #f5f7fa;
  padding: 20px;
}

.app-footer {
  background-color: #2c3e50;
  color: white;
  text-align: center;
  padding: 20px;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
}

.footer-content p {
  margin: 0;
  font-size: 14px;
  opacity: 0.8;
}

/* 全局样式 */
#app {
  font-family: 'Microsoft YaHei', 'Arial', sans-serif;
}

.el-button {
  border-radius: 6px;
}

.el-card {
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
</style>
